View Javadoc

1   /*
2    * The ReWinder Project
3    * 
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU General Public License
6    * as published by the Free Software Foundation; either version 2
7    * of the License, or (at your option) any later version.
8   
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13  
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17   */
18  package ch.twiddlefinger.inet.rewinder.resource;
19  
20  import java.awt.image.BufferedImage;
21  
22  import java.io.File;
23  import java.io.FileNotFoundException;
24  import java.io.FileOutputStream;
25  import java.io.IOException;
26  
27  import java.net.URL;
28  
29  import javax.imageio.ImageIO;
30  
31  import javax.swing.ImageIcon;
32  
33  
34  /***
35   * @author matthias.vonrohr To change the template for this generated type
36   *         comment go to Window>Preferences>Java>Code
37   *         Generation>Code and Comments
38   */
39  public class Resource {
40      public static URL getURL(String name) {
41          return (Resource.class).getResource(name);
42      }
43  
44      public static URL getReplay(String name) {
45          return getURL("replay/" + name);
46      }
47  
48      public static BufferedImage getImage(String name) {
49          try {
50              return ImageIO.read(Resource.getURL("image/" + name));
51          } catch (IOException e) {
52              return null;
53          }
54      }
55  
56      public static ImageIcon getIcon(String name) {
57          return new ImageIcon(Resource.getURL("image/" + name));
58      }
59  
60      public static FileOutputStream getDumpFile(String name)
61          throws FileNotFoundException {
62          File file = new File(getURL("dump/" + name).getPath());
63  
64          return new FileOutputStream(file);
65      }
66  
67      /***
68       * @param bs
69       * @param string
70       */
71      public static void saveData(byte[] bs, String filename) {
72          try {
73              FileOutputStream out = getDumpFile(filename);
74              out.write(bs);
75          } catch (Exception e) {
76              e.printStackTrace();
77          }
78      }
79  }